package tugas.akhir.jason;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class dr8_mulmed extends Activity{
	/** Called when the activity is first created. */
    
	private String labelId, labelAlamat;
	private Button simpan;
	Button dr8_camera_button;
	Button dr8_audio_button;
	Button dr8_notes_button;
	DBAdapter db;
	protected MyDBHelper myDBHelper;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dr8_mulmed);
        
        TextView rid = (TextView) findViewById (R.id.dr5_reportid_label);
        labelId = "ID Laporan: " + variabelstatis.idglobal;
        rid.setText (labelId);
        

        //alamat
        TextView address = (TextView) findViewById (R.id.dr5_address_label);
        labelAlamat = "Alamat: " + variabelstatis.alamatglobal;
        address.setText (labelAlamat);
        
        dr8_camera_button = (Button) findViewById(R.id.dr8_camera_button);
        dr8_notes_button = (Button) findViewById(R.id.dr8_notes_button);
        
        simpan = (Button)this.findViewById(R.id.SimpanLaporan);
		simpan.setOnClickListener(onSave);
		
		db = new DBAdapter(this);
		myDBHelper=new MyDBHelper(this);
        
        dr8_camera_button.setOnClickListener(new View.OnClickListener() {
    		public void onClick(View view)
    		  { startActivity(new Intent(dr8_mulmed.this, dr8_cameramiddas.class)); }
    	});
        
        dr8_notes_button.setOnClickListener(new View.OnClickListener() {
    		public void onClick(View view)
    		  { startActivity(new Intent(dr8_mulmed.this, dr8_notes.class)); }
    	});
        
        
    }
	
	private View.OnClickListener onSave=new View.OnClickListener() {
		
		public void onClick(View v) {
			
			SQLiteDatabase dbimage = myDBHelper.getReadableDatabase();
	 	    ContentValues values = new ContentValues();
	 	    values.put("image", variabelstatis.image);
	 	    dbimage.insert("storedImages", variabelstatis.idglobal, values);
			
	        db.open();        
	        	db.insertTitle(
	        		variabelstatis.idglobal,
	        		variabelstatis.longitude,
	        		variabelstatis.latitude,
	        		variabelstatis.alamatglobal,
	        		variabelstatis.imeii,
	        		variabelstatis.timestamp,
	        		variabelstatis.dr01_namafasilitasumum,
	        		variabelstatis.dr01_alamatfasilitasumum,
	        		variabelstatis.dr02_namakantor,
	        		variabelstatis.dr02_alamatkantor,
	        		variabelstatis.dr02_namapemilik,
	        		variabelstatis.dr02_nomorkontakpemilik,
	        		variabelstatis.dr02_jumlahlantairusak,
	        		variabelstatis.dr2_toogle,
	        		variabelstatis.dr2_buttonpemilik,
	        		variabelstatis.dr2_buttonpenyewa,
	        		variabelstatis.dr2_namapenghuni,
	        		variabelstatis.dr2_nomorkontak,
	        		variabelstatis.dr2_jumlahpenghuni,
	        		variabelstatis.dr3_asuransibangunan,
	        		variabelstatis.dr3_asuransibarangpersonal,
	        		variabelstatis.dr3_asuransijiwa,
	        		variabelstatis.dr3_tidakada,
	        		variabelstatis.dr3_tidakdiketahui,
	        		variabelstatis.dr4_gempabumi,
	        		variabelstatis.dr4_tsunami,
	        		variabelstatis.dr4_gunungmeletus,
	        		variabelstatis.dr4_banjir,
	        		variabelstatis.dr4_kebakaran,
	        		variabelstatis.dr4_angintopan,
	        		variabelstatis.dr4_tanahlongsor,
	        		variabelstatis.dr4_lainlain,
	        		variabelstatis.dr5_kategorikerusakan,
	                variabelstatis.headerdata
	        		);
	        	db.close();
	        
	        	if (variabelstatis.jenisbangunan == "rumah"){ 
	   	        	db.open();
	   	        	db.insertrumah(
	   		        		variabelstatis.idglobal,
	   		        		variabelstatis.timestamp,
	   		        		variabelstatis.longitude,
	   		        		variabelstatis.latitude,
	   		        		variabelstatis.alamatglobal,
	   		        		variabelstatis.dr2_namapenghuni,
	   		        		variabelstatis.dr2_nomorkontak,
	   		        		variabelstatis.dr2_jumlahpenghuni,
	   		        		variabelstatis.dr3_asuransi,
	   	        			variabelstatis.dr4_penyebabkerusakan,
	   		        		variabelstatis.dr5_kategorikerusakan,
	   	        			variabelstatis.catatan,
	   	        			variabelstatis.image);
	   	        	
	   	        db.close();
	   	        }
	        	   
	        	if (variabelstatis.jenisbangunan == "kantor"){ 
	   	        	db.open();
	   	        	db.insertkantor(
	   		        		variabelstatis.idglobal,
	   		        		variabelstatis.timestamp,
	   		        		variabelstatis.longitude,
	   		        		variabelstatis.latitude,
	   		        		variabelstatis.dr02_namakantor,
	   		        		variabelstatis.dr02_alamatkantor,
	   		        		variabelstatis.dr02_namapemilik,
	   		        		variabelstatis.dr02_nomorkontakpemilik,
	   		        		variabelstatis.dr02_jumlahlantairusak,
	   	        			variabelstatis.dr4_penyebabkerusakan,
	   		        		variabelstatis.dr5_kategorikerusakan,
	   	        			variabelstatis.catatan,
	   	        			variabelstatis.image);
	   	        	
	   	        db.close();
	   	        }
	        	
	        	
	        if (variabelstatis.jenisbangunan == "fasilitasumum"){ 
	        	db.open();
	        	db.insertfasilitasumum(
		        		variabelstatis.idglobal,
		        		variabelstatis.timestamp,
		        		variabelstatis.longitude,
		        		variabelstatis.latitude,
		        		variabelstatis.dr01_namafasilitasumum,
		        		variabelstatis.dr01_alamatfasilitasumum,
	        			variabelstatis.dr4_penyebabkerusakan,
		        		variabelstatis.dr5_kategorikerusakan,
	        			variabelstatis.catatan,
	        			variabelstatis.image);
	        	
	        db.close();
	        }	       
	        
			{ startActivity(new Intent(dr8_mulmed.this,laporan.class)); }
		}
	};
}